package com.bank.service.impl;

import com.bank.entity.CardInfo;
import com.bank.mapper.CardInfoMapper;
import com.bank.service.CardInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 银行卡信息服务实现类
 */
@Service
public class CardInfoServiceImpl implements CardInfoService {

    @Autowired
    private CardInfoMapper cardInfoMapper;

    @Override
    public List<CardInfo> findAll() {
        return cardInfoMapper.findAll();
    }

    @Override
    public CardInfo findById(String cardID) {
        return cardInfoMapper.findById(cardID);
    }

    @Override
    public List<CardInfo> findByCustomerId(Long customerID) {
        return cardInfoMapper.findByCustomerId(customerID);
    }

    @Override
    @Transactional
    public boolean add(CardInfo cardInfo) {
        return cardInfoMapper.insert(cardInfo) > 0;
    }

    @Override
    @Transactional
    public boolean update(CardInfo cardInfo) {
        return cardInfoMapper.update(cardInfo) > 0;
    }

    @Override
    @Transactional
    public boolean reportLoss(String cardID) {
        return cardInfoMapper.updateReportLoss(cardID, "是") > 0;
    }

    @Override
    @Transactional
    public boolean updatePassword(String cardID, String oldPass, String newPass) {
        return cardInfoMapper.updatePassword(cardID, oldPass, newPass) > 0;
    }

    @Override
    @Transactional
    public boolean delete(String cardID) {
        return cardInfoMapper.deleteById(cardID) > 0;
    }
} 